package com.prs.crm.action.person;

import org.apache.struts2.convention.annotation.Action;
import org.apache.struts2.convention.annotation.Result;
import org.courser.struts.BaseAction;
import org.courser.ui.PaginationSupport;
import org.hibernate.criterion.DetachedCriteria;

import com.prs.crm.domain.person.StaffSex;
import com.prs.crm.service.person.StaffSexService;

public class StaffSexAction extends BaseAction{

	private static final long serialVersionUID = 1L;
	
	private Integer[] ids;
	private PaginationSupport pagination;
	private StaffSex staffSex;
	private StaffSexService staffSexService;
	public Integer[] getIds() {
		return ids;
	}
	public void setIds(Integer[] ids) {
		this.ids = ids;
	}
	public PaginationSupport getPagination() {
		return pagination;
	}
	public void setPagination(PaginationSupport pagination) {
		this.pagination = pagination;
	}
	public StaffSex getStaffSex() {
		return staffSex;
	}
	public void setStaffSex(StaffSex staffSex) {
		this.staffSex = staffSex;
	}
	public StaffSexService getStaffSexService() {
		return staffSexService;
	}
	public void setStaffSexService(StaffSexService staffSexService) {
		this.staffSexService = staffSexService;
	}
	
	@Action("listStaffSex")
	public String listStaffSex(){
		DetachedCriteria criteria=this.getPaginationHelper().createQuery(StaffSex.class);
		pagination=this.getPaginationHelper().prepare(pagination);
		this.setPagination(this.getStaffSexService().listByPage(criteria, pagination));
		return SUCCESS;
	}
	
	@Action("editStaffSex")
	public String editStaffSex(){
		if(ids!=null){
			this.staffSex=this.getStaffSexService().get(ids[0]);
		}
		return SUCCESS;
	}
	
	@Action(value="saveStaffSex",results={
			@Result(name="success",type="redirect",location="listStaffSex"),
			@Result(name="error",type="chain",location="editStaffSex")
	})
	public String saveStaffSex(){
		this.getStaffSexService().save(staffSex);
		return SUCCESS;
	}
	
	@Action(value="removeStaffSex",results={
			@Result(name="success",type="redirect",location="listStaffSex"),
			@Result(name="error",type="chain",location="listStaffSex")
	})
	public String removeStaffSex(){
		if (ids==null) {
			this.addActionError("请选择一行进行操作!");
			return ERROR;
		}
		this.getStaffSexService().batchRemove(ids);
		return SUCCESS;
	}
}
